package cn.tedu.smartos.family_user.pojo.vo;

import cn.tedu.smartos.family_user.pojo.entity.ElectronicFence;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.text.SimpleDateFormat;

@Data
public class ElectronicFenceVO {
    @ApiModelProperty(value = "围栏ID")
    private Long fenceId;
    @ApiModelProperty(value = "老人用户ID")
    private Long elderlyUserId;
    @ApiModelProperty(value = "家属用户ID")
    private Long familyUserId;
    @ApiModelProperty(value = "围栏名称")
    private String fenceName;
    @ApiModelProperty(value = "围栏状态：0-禁用，1-启用")
    private Integer status;
    @ApiModelProperty(value = "中心点纬度")
    private Double centerLatitude;
    @ApiModelProperty(value = "中心点经度")
    private Double centerLongitude;
    @ApiModelProperty(value = "围栏半径（米）")
    private Double radius;
    @ApiModelProperty(value = "越界报警消息")
    private String alertMessage;
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String createTime;
    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String updateTime;
    @ApiModelProperty(value = "最后检测状态：0-围栏内，1-围栏外")
    private Integer lastStatus;
    @ApiModelProperty(value = "最后检测时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String lastCheckTime;

    public ElectronicFenceVO(ElectronicFence fence) {
        this.fenceId = fence.getFenceId();
        this.elderlyUserId = fence.getElderlyUserId();
        this.familyUserId = fence.getFamilyUserId();
        this.fenceName = fence.getFenceName();
        this.status = fence.getStatus();
        this.centerLatitude = fence.getCenterLatitude();
        this.centerLongitude = fence.getCenterLongitude();
        this.radius = fence.getRadius();
        this.alertMessage = fence.getAlertMessage();
//        格式化 时间符合@JsonFormat定义
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        this.createTime = sdf.format(fence.getCreateTime());
//        this.createTime = fence.getCreateTime().toString();
//        this.updateTime = fence.getUpdateTime().toString();
        this.updateTime = sdf.format(fence.getUpdateTime());
        this.lastStatus = fence.getLastStatus();
        this.lastCheckTime = fence.getLastCheckTime() != null ?
                fence.getLastCheckTime().toString() : null;
    }
}